package com.nsw99;

import java.io.IOException;
import java.util.Properties;

/**
 * @author helin
 * @email hl_0074@sina.com
 * @date 2016年8月9日
 */
public class ConfigLoader {

	private static Properties properties = new Properties();

	public static String get(String key) {

		return properties.getProperty(key);
	}

	public static String get(String key, String dlft) {

		return properties.getProperty(key, dlft);
	}

	public static int getInt(String key) {

		return getInt(key, -1);
	}

	public static int getInt(String key, int dflt) {

		String value = get(key);
		if (value == null) { return dflt; }

		try {
			return Integer.parseInt(value);
		} catch (NumberFormatException e) {
			return dflt;
		}
	}

	public static void load(String config) {

		try {
			properties.load(ConfigLoader.class.getResourceAsStream("/" + config));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
